package com.zb.service.impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.Employee;
import com.zb.entity.PageData;
import com.zb.mapper.EmployeeMapper;
import com.zb.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    //分页查询员工
    @Override
    public PageData pageSelect(Integer page, Integer pageSize, String name) {
        LambdaQueryWrapper<Employee> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(!StringUtils.isEmpty(name), Employee::getName, name);
        Page<Employee> empPage = new Page<>(page, pageSize);
        IPage<Employee> empIpage = employeeMapper.selectPage(empPage, lambdaQueryWrapper);
        PageData data = new PageData<Employee>();
        data.setPage((int) empIpage.getPages());
        data.setPageSize((int) empIpage.getSize());
        data.setTotal((int) empIpage.getTotal());
        data.setList(empIpage.getRecords());
        return data;
    }

    //查询所有
    @Override
    public List<Employee> selectAllEmp() {
        return employeeMapper.selectList(null);
    }


    //删除员工
    @Override
    public Integer deleteEmpById(String empId) {
        return employeeMapper.deleteById(empId);
    }

    //更新员工信息
    @Override
    public Integer updateEmpInfo(Employee employee) {
        return employeeMapper.updateById(employee);
    }
}
